<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta
      name="viewport"
      content="width=device-width, initial-scale=1, maximum-scale=1,minimum-scale=1, user-scalable=no"
    />
    <title>js常规运算符</title>
    <link rel="shortcut icon" href="../favicon.ico" type="image/x-icon" />
  </head>
  <body>
    <div class="box"></div>
    <script>
      // 1 数学运算符 + - * / % ++ -- & |
      let a = 2
      let b = 3.14
      console.log(a + b) // 5.140000000000001
      console.log(a - b) // -1.1400000000000001
      console.log(a * b) // 6.28
      console.log(a / b) // 0.6369426751592356
      console.log(b % a) // 1.1400000000000001
      console.log(a++) // 2
      console.log(--a) // 2
      console.log(1 | 2) // 3

      // 2 赋值运算符 = += -= /= %=
      let n = 20
      n += 10
      n++
      console.log(n) // 31
      console.log(n % 2) // 1

      // 3 比较(关系)运算符 > < >= <= != == === !==
      console.log(1 > 2) // false
      console.log(1 != 2) // true
      console.log(1 == 1) // true
      console.log('1' == 1) // true
      console.log('1' === 1) // false ===恒等，不仅比较值还判断类型，以后只能使用===判断是否相等
      console.log('1' !== 1) // true

      // 4 逻辑运算符 && || ！
      let rt = 1 > 2 || 2 > 1 // true
      if (!rt) {
        console.log(false)
      } else {
        console.log('rt=', rt)
      }

      // 键盘输入两个数判断两个值是否相等?
      let num1 = prompt('输入第1个数:', 0)
      let num2 = prompt('输入第2个数:', 0)
      // 表单 输入框内输入的数据都是字符串，不能直接进行四则运算，要转换为number类型才行
      console.log(num1, num2, typeof num1, typeof num2)
      // 转换数据类型
      num1 = parseInt(num1)
      num2 = parseInt(num2)
      console.log(num1, num2, typeof num1, typeof num2)
      if (num1 === num2) {
        console.log(`num1===num2,num1=${num1}`)
      } else {
        console.log(`num1=${num1},num2=${num2}`)
      }
    </script>
  </body>
</html>
